package com.shou.domain.fee.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shou.domain.common.AbstractService;
import com.shou.domain.common.PageQueryEntity;
import com.shou.domain.fee.model.FeeScheduleEntity;
import com.shou.domain.fee.repository.IFeeScheduleRepository;
import com.shou.domain.fee.service.IFeeScheduleService;
import com.shou.types.common.TableNameEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Nemo
* @description 针对表【feeschedules(收费标准表，存储不同的收费策略)】的数据库操作Service实现
* @createDate 2025-02-07 22:10:51
*/
@Service
public class FeeScheduleService extends AbstractService implements IFeeScheduleService {
    @Resource
    private IFeeScheduleRepository feeScheduleRepository;
    @Override
    public void insertFeeSchedule(FeeScheduleEntity feeScheduleEntity) {
        validateFeeScheduleEntity(feeScheduleEntity);
        feeScheduleRepository.insert(feeScheduleEntity);
    }

    @Override
    public FeeScheduleEntity getFeeScheduleById(Integer id) {
        return feeScheduleRepository.getFeeScheduleById(id);
    }

    @Override
    public IPage<FeeScheduleEntity> pageQuery(PageQueryEntity pageQueryEntity) {
        pageQueryEntity.setSortName(camelToSnake(pageQueryEntity.getSortName()));
        validateQueryParams(pageQueryEntity, TableNameEnum.FEE_SCHEDULE);
        return feeScheduleRepository.getFeeSchedulesPage(pageQueryEntity);
    }

    @Override
    public void updateFeeScheduleById(FeeScheduleEntity feeScheduleEntity) {
        Integer id = feeScheduleEntity.getId();
        if(id == null || !checkIfExistById(id, TableNameEnum.FEE_SCHEDULE)){
            throw new RuntimeException("id为" + id + "的记录不存在");
        }
        validateFeeScheduleEntity(feeScheduleEntity, feeScheduleEntity.getId());
        feeScheduleRepository.updateFeeScheduleById(feeScheduleEntity);
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        super.deleteByIds(ids, TableNameEnum.FEE_SCHEDULE);
    }

    @Override
    public void deleteAll() {
        super.deleteAll(TableNameEnum.FEE_SCHEDULE);
    }

    private void validateFeeScheduleEntity(FeeScheduleEntity feeSchedule, Integer... excludeIds) {
        validateCode(feeSchedule.getCode(), TableNameEnum.FEE_SCHEDULE.getEnTableName(), excludeIds);
    }
}




